import type { ExamRecord, SaveExamRecordParams, ExamStatistics, CommonResult } from '@/types'
import { http } from '@/utils/http'
import { getBusinessApiPrefix } from '@/utils/config'

/**
 * 保存测试记录（主表+明细表）
 * @param params 测试记录参数
 */
export const saveExamRecordAPI = (params: SaveExamRecordParams) => {
	return http<CommonResult>({
		url: `${getBusinessApiPrefix()}/examRecords/saveExamRecordAPI`,
		method: 'POST',
		data: params,
	})
}

/**
 * 获取测试记录列表
 * @param techCode 技术栈编码（可选）
 */
export const getExamRecordsAPI = (techCode?: string) => {
	return http<ExamRecord[]>({
		url: `${getBusinessApiPrefix()}/examRecords/getExamRecordsAPI`,
		method: 'POST',
		data: { techCode },
	})
}

/**
 * 获取测试记录题目详情
 * @param examRecordId 测试记录ID
 */
export const getExamRecordQuestionsAPI = (examRecordId: number) => {
	return http<CommonResult>({
		url: `${getBusinessApiPrefix()}/examRecords/getExamRecordQuestionsAPI`,
		method: 'POST',
		data: { examRecordId },
	})
}

/**
 * 删除测试记录
 * @param id 测试记录ID
 */
export const deleteExamRecordAPI = (id: number) => {
	return http<CommonResult>({
		url: `${getBusinessApiPrefix()}/examRecords/deleteExamRecordAPI`,
		method: 'POST',
		data: { id },
	})
}

/**
 * 获取考试记录统计信息
 */
export const getExamStatisticsAPI = () => {
	return http<ExamStatistics>({
		url: `${getBusinessApiPrefix()}/examRecords/getExamStatisticsAPI`,
		method: 'POST',
		data: {},
	})
}

/**
 * 清空所有考试记录
 */
export const clearAllExamRecordsAPI = () => {
	return http<CommonResult>({
		url: `${getBusinessApiPrefix()}/examRecords/clearAllExamRecordsAPI`,
		method: 'POST',
		data: {},
	})
}
